#pragma once

#include <iostream>
#include <string>
#include <functional>

class Reactor;
class Connection;
using func_t = std::function<void(Connection *)>;

class Connection
{
public:
    Connection(int fd)
        : _sockfd(fd), _R(nullptr)
    {
    }
    void Register(func_t recver, func_t sender, func_t excepter)
    {
        _recver = recver;
        _sender = sender;
        _excepter = excepter;
    }
    void SetEvents(uint32_t events)
    {
        _events = events;
    }
    void SetSelf(Reactor* self)
    {
        _R = self;
    }
    void AppendInbuff(const std::string& buff)
    {
        _inbuffer += buff;
    }
    int GetSockfd()
    {
        return _sockfd;
    }
    std::string& Inbuffer()
    {
        return _inbuffer;
    }
    ~Connection()
    {
    }

private:
    int _sockfd; // 文件描述符
    std::string _inbuffer;
    std::string _outbuffer;

    uint32_t _events;
public:
    func_t _recver;
    func_t _sender;
    func_t _excepter;

    Reactor* _R;
};